package ${properties.packageName}.${properties.moduleName}.controller;


import javax.annotation.Resource;

import com.tangguangdi.base.common.entity.web.Result;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangguangdi.base.common.basic.PermissionRule;
import com.tangguangdi.base.common.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ${properties.packageName}.${properties.moduleName}.entity.${entity};
import ${properties.packageName}.${properties.moduleName}.service.I${entity}Service;


import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * ${properties.tableComment!} 前端控制器
 * </p>
 *
 * @author ${properties.author}
 * @since ${currentDate}
 */
@RestController
@RequestMapping("${properties.moduleName}/${name}")
@Api(tags = {"${properties.tableComment!}"})
public class ${entity}Controller {

    @Resource
    private I${entity}Service ${name}Service;

    /**
     * ${properties.tableComment!}列表
     */
    @GetMapping("list")
    @ApiOperation("${properties.tableComment!}列表")
    @Permission(rule = PermissionRule.Login)
    public Result<List<${entity}>> list() {
        QueryWrapper<${entity}> wrapper = new QueryWrapper<>();
        return new Result<List<${entity}>>()
                .setSuccess(true)
                .setData(${name}Service.list(wrapper));
    }

    /**
     * ${properties.tableComment!}分页
     */
    @GetMapping
    @ApiOperation("${properties.tableComment!}分页")
    @Permission(rule = PermissionRule.Login)
    public Result<Page<${entity}>> page(Page<${entity}> page) {
        QueryWrapper<${entity}> wrapper = new QueryWrapper<>();
        return new Result<Page<${entity}>>()
                .setSuccess(true)
                .setData(${name}Service.page(page, wrapper));
    }

    /**
     * ${properties.tableComment!}新增
     */
    @PostMapping
    @ApiOperation("${properties.tableComment!}新增")
    @Permission(rule = PermissionRule.Login)
    public Result save(@RequestBody ${entity} ${name}) {
        ${name}.setId(null);
        ${name}Service.save(${name});
        return new Result().setSuccess(true).setMessage("新增${properties.tableComment!}成功");
    }

    /**
     * ${properties.tableComment!}删除
     */
    @DeleteMapping("{id}")
    @ApiOperation("${properties.tableComment!}删除")
    @Permission(rule = PermissionRule.Login)
    public Result removeById(@PathVariable Long id) {
        ${name}Service.removeById(id);
        return new Result().setSuccess(true).setMessage("删除${properties.tableComment!}成功");
    }

    /**
     * ${properties.tableComment!}修改
     */
    @PutMapping
    @ApiOperation("${properties.tableComment!}修改")
    @Permission(rule = PermissionRule.Login)
    public Result updateById(@RequestBody ${entity} ${name}) {
        ${name}Service.updateById(${name});
        return new Result().setSuccess(true).setMessage("修改${properties.tableComment!}成功");
    }
}
